//返回上一个页面
$('.btn-back').on('click', function() {
    $(this).attr('href', '../views/coupon.html');
})
$(function() {
    // 封装获取地址栏参数的函数
    function getdataForSearch() {
        var path = decodeURI(location.search.substr(1));
        // console.log(path);
        var arr = path.split('&');
        // console.log(arr);
        var caObj = {};
        for (var i = 0; i < arr.length; i++) {
            var temp = arr[i].split('=');
            caObj[temp[0]] = temp[1];
        }
        // console.log(caObj);
        return caObj;
    }

    var couponid = getdataForSearch().couponid;
    var titleName = getdataForSearch().title;
    var name = titleName + "优惠券";
    $('.title').html(name);

    $.ajax({
        type: "get",
        url: "http://193.112.55.79:9090/api/getcouponproduct",
        data: { couponid: couponid },
        dataType: "json",
        success: function(res) {
            // console.log(res);
            var html = template("couponListTmp", res);
            var htmlTb = template("imageTmp", res);
            $("ul").html(html);
            $(".img_path").html(htmlTb);
        }
    });

    // 从被点击的图片开始轮播
    $('ul').on('click', 'li', function() {
        var index = $(this).index();
        console.log($('.img_path > div').eq(index))
        $('.img_path > div').eq(index).addClass('active');
    });




    function back() {
        history.go(-1);
    }
    $('.btn-back').click(function() {
        back();
    })
})